{template 'common/header'}
<ul class="nav nav-tabs">
	<li {if $op == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('codescore', array('op' => 'post'))}">添加活动</a></li>
	<li {if $op == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('codescore')}">活动管理</a></li>
</ul>
<style>
th{
	text-align: center !important;
}
td{
	text-align: center !important;
	white-space: normal !important;
	word-break: break-all !important;
}
</style>
{if $op == 'post'}
{php load()->func('tpl')}
<div class="main">
	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
	<input type="hidden" name="id" value="{$id}" />
        <div class="panel panel-default">
            <div class="panel-heading">
                活动设置
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动标题</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="title" class="form-control" value="{$item['title']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动关键字</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="kword" class="form-control" value="{$item['kword']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">引导输入口令提示语</label>
                    <div class="col-sm-9 col-xs-12">
                        <textarea name="kwtips" class="form-control">{$item['kwtips']}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动时间</label>
                    <div class="col-sm-9 col-xs-12">
                        {php echo tpl_form_field_daterange('datelimit', array('start'=>date('Y-m-d H:i',$item['starttime']),'end'=>date('Y-m-d H:i',$item['endtime'])), true)}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动未开始</label>
                    <div class="col-sm-9 col-xs-12">
                        <textarea name="nostarttips" class="form-control">{$item['nostarttips']}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">获得积分提示语</label>
                    <div class="col-sm-9 col-xs-12">
                        <textarea name="endtips" class="form-control">{$item['endtips']}</textarea>
                    </div>
                </div>
                
                <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">卡密文件</label>
					<div class="col-sm-4">
						<input type="file" name="codes"  class="form-control">
						{if $item}<div class='help-block'>新导入的卡密文件，会增加到已有的卡密库</div>{/if}
					</div>
				</div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">卡密对应积分</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="score" class="form-control" value="{$item['score']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">获得积分提示语</label>
                    <div class="col-sm-9 col-xs-12">
                        <textarea name="scoretips" class="form-control">{$item['scoretips']}</textarea>
                        <div class='help-block'>#积分#代表粉丝当前获得的积分；#总分#代表粉丝总积分</div>
                    </div>
                </div>
            </div>
        </div>

        <input name="submit" type="submit" value="提交" class="btn btn-primary span3">
        <input type="hidden" name="token" value="{$_W['token']}" />
	</form>
</div>
{elseif $op == 'display'}
<div class="main">
	<div style="background: white;">
		<table class="table table-hover">
			<thead>
				<tr>
					<th>活动标题</th>
					<th>关键字</th>
					<th>时间</th>
					<th>口令总数量</th>
					<th>已使用口令</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $c}
				<tr>
					<td>{$c['title']}</td>
					<td>
						{$c['kword']}
					</td>
					<td>
					开始时间：{php echo date('Y-m-d H:i',$c['starttime'])}<br>结束时间：{php echo date('Y-m-d H:i',$c['endtime'])}
					</td>
					<td>{$c['total']}</td>
					<td>{$c['use']}</td>
					<td>
						<a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('codescore', array('op' => 'post', 'id' => $c['id']))}">编辑</a>
						<a class="btn btn-success btn-sm" target="_blank" href="{php echo $this->createWebUrl('codescore', array('op' => 'code', 'aid' => $c['id']))}">卡密查看</a>
						<a class="btn btn-danger btn-sm" href="{php echo $this->createWebUrl('codescore', array('op' => 'delete', 'id' => $c['id']))}" onclick="return confirm('确认删除此类别吗？');">删除</a>
					</td>
				</tr>
				{/loop}
			</tbody>
		</table>
		{$pager}
	</div>
</div>
{elseif $op == 'code'}
<div class="main">
	<div style="background: white;">
		<table class="table table-hover">
			<thead>
				<tr>
					<th>口令</th>
					<th>积分</th>
					<th>状态</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $c}
				<tr>
					<td>{$c['code']}</td>
					<td>{$c['score']}</td>
					<td>
					{if $c['mid']}
					<img src="{$mems[$c['mid']]['avatar']}" style="width: 60px;"><br>{$mems[$c['mid']]['nickname']}<br>
					使用时间：{php echo date('Y-m-d H:i',$c['usetime'])}
					{else}
					<label class='label label-default'>未使用</label>
					{/if}
					</td>
					<td>
						<a class="btn btn-danger btn-sm" href="{php echo $this->createWebUrl('codescore', array('op' => 'delete', 'id' => $c['id']))}" onclick="return confirm('确认删除此类别吗？');">删除</a>
					</td>
				</tr>
				{/loop}
			</tbody>
		</table>
		{$pager}
	</div>
</div>
{/if}
